// pages/exchange/index.js
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    img: '../../image/Ordermanagement_1.png',
    out: App.Imges.out,
    start:false,
    list:[],
    order:[],
    power_id: -1,
    power_order_id: -1
  },
  cancel(e){
    console.log(e)
    let power_id = e.currentTarget.dataset.powerid, power_order_id = e.currentTarget.dataset.id;
    this.setData({
      start: true,
      power_id: power_id,
      power_order_id: power_order_id
    })
  },
  cancelOut(e){
    
    let that = this, power_id = this.data.power_id, order = this.data.order, power_order_id = this.data.power_order_id;
    App.ajax('mp/power/cancel', 'POST', { staff_id: order.id, power_id: power_id, power_order_id: power_order_id  }).then(res => {
      this.power();
      this.setData({
        start: false
      })
    }).catch(err => {
      console.log('报错了', err)
    })
    
  },
  out(){
    this.setData({
      start: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  power(){
    let that = this, list = this.data.list, order = this.data.order;
    App.ajax('mp/power/detail', 'GET', { staff_id:order.id}).then(res => {
      list = [...res.data];
      this.setData({
        list
      })
    }).catch(err => {
      console.log('报错了', err)
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that=this;
  
    App.UserInfo((res) => {
      this.setData({
        order: res
      },()=>{
        this.power();
      })
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.power();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})